<!--
 * @Author: lmk
 * @Date: 2022-04-15 22:27:06
 * @LastEditTime: 2022-07-01 11:13:52
 * @LastEditors: lmk
 * @Description: 
-->
<template>
  <pageView pageName="news" @getSearchValue="getSearchValue"  bannerImage="/img/banner/newbanner.png">
    <div class="content-view">
      <swiper
        class="swiper-container"
        :modules="modules"
        :pagination="{
          el: '.pagination',
          clickable: true
        }"
        @slideChange='onSlideChange'
        :virtual="true"
      >
        <swiper-slide
          v-for="(slideContent, index) in state.slides"
          :key="index"
          :virtualIndex="index">
            <div v-for="(item,index) in slideContent" :key="index" class="flex news-item">
              <img :src="item.informationFigureImage" alt="" class="img flex-none">
              <div class="flex-grow">
                <div>
                  <p class="item-title">{{isZh ? item.informationTitle : item.informationTitleEnglish}}</p>
                  <img src="/img/activity/a-line.png" alt="">
                  <p class="item-desc line-clamp-4">
                    {{isZh ? getElementText(item.informationDesc) : getElementText(item.informationDescEnglish)}}
                  </p>
                </div>
                <p class="detail" @click="detail(item)" >{{$t('news.viewAll')}}>></p>
              </div>
            </div>
          </swiper-slide>
      </swiper>
      <div class="pagination"></div>
    </div>
  </pageView>
</template>

<script>
import pageView from '@/components/pageView'
import { Pagination,Virtual } from 'swiper';
import { Swiper, SwiperSlide } from "swiper/vue/swiper-vue";

import "swiper/swiper-bundle.css";
import { reactive, ref } from '@vue/reactivity';
import {  pageWebsiteInformation } from '@/api/api';
import { useIsZh } from '@/utils/useIsZh';
import { useRouter } from 'vue-router';
import { getElementText } from "@/utils";
export default {
  setup() {
    const {isZh} = useIsZh()
    const activeIndex = ref(0)
    // 获取当月数据
    const state = reactive({
      slides:[],
      current:1,
      informationName:''
    })
    // 监听index变化
    const onSlideChange = (swiper) => {
      state.current = swiper.activeIndex + 1;
      if(!state.slides[state.current - 1]){
        getList()
      }
    };
    // 获取列表
    const getList = ()=>{
      pageWebsiteInformation({
        size:4,
        current:state.current,
        informationName:state.informationName
      }).then(res=>{
        if(state.slides.length === 0) state.slides = new Array(res.pages);
        if(state.slides.length>0){
          state.slides[state.current - 1] = res.records
        }
      })
    }
    getList()
    // 获取搜索条件
    const getSearchValue = (value) => {
      state.current = 1;
      state.informationName = value
      getList()
    }
    const router = useRouter()
    // 跳转详情
    const detail = item=>{
      router.push(`/news/${item.informationId}`)
    }
    return {
      onSlideChange,
      activeIndex,
      state,
      getSearchValue,
      isZh,
      detail,
      modules:[Pagination,Virtual],
      getElementText
    };
  },
  components: {
    pageView,
    Swiper,
    SwiperSlide,
  }
}
</script>
<style lang="scss" scoped>
@media screen and (min-width: 1401px) {
  .news-item{
    margin-bottom: 20px;
  }
  .img{
    width: 518px;
    height: 358px;
    border: 1px solid $activeTxt;
    margin-right: 20px;
  }
  .flex-grow{
    background: #FFFAF5;
  }

  .item{
    &-title{
      font-size: 24px;
      font-weight: bold;
      color: #202020;
      margin-bottom: 30px;
      margin-left: 80px;
      margin-top: 50px;
    }
    &-desc{
      font-size: 14px;
      font-weight: bold;
      margin-left: 80px;
      color: #666666;
      line-height: 30px;
      margin-right: 86px;
      margin-top: 30px;
      text-indent: 2em;
    }
  }
  .line{
    width: 20px;
    height: 4px;
    background: $activeTxt;
    margin-bottom: 20px;
    margin-top: 13px;
    margin-left: 80px;
  }
  .detail{
    font-size: 14px;
    font-weight: 400;
    color: $activeTxt;
    margin-right: 86px;
    text-align: right;
    margin-top: 30px;
    cursor: pointer;
  }
}
@media screen and (max-width: 1400px) {
  .news-item{
    margin-bottom: 10px;
    display: block;
  }
  .img{
    height: calc((100vw - 30px) * 0.75);
    border: 1px solid $activeTxt;
    width: 100%;
    object-fit: cover;
  }
  .flex-grow{
    background: #FFFAF5;
    padding: 10px;
    margin-top: 10px;
  }

  .item{
    &-title{
      font-size: 12px;
      font-weight: bold;
      color: #202020;
      margin-bottom: 15px;
    }
    &-desc{
      font-size: 7px;
      font-weight: bold;
      color: #666666;
      line-height: 15px;
      margin-top: 15px;
      text-indent: 2em;
    }
  }
  .line{
    width: 20px;
    height: 4px;
    background: $activeTxt;
    margin-bottom: 10px;
    margin-top: 13px;
  }
  .detail{
    font-size: 7px;
    font-weight: 400;
    color: $activeTxt;
    text-align: right;
    cursor: pointer;
  }
}
</style>